<template>
    <JVxeTable ref="tableRef" row-number   :loading="loading" bordered
        :loading-config="{ icon: 'vxe-icon-indicator roll', text: '正在拼命加载中...' }" :dataSource="dataSource"
        :columns="columns" style="margin-top: 8px">
        <template #toolbarAfter>
            <a-space>
                <a-button @click="flushStock" type="primary">更新库存</a-button>
                <a-button @click="loadData" type="primary">查询</a-button>
            </a-space>
        </template>
    </JVxeTable>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { Popconfirm } from 'ant-design-vue';
import { JVxeColumn, JVxeTableInstance, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
import { useMessage } from '/@/hooks/web/useMessage';
import { list, listAsync, flushstock } from './TmStockList.api';
const tableRef = ref < JVxeTableInstance > ();
const { createMessage } = useMessage();
const loading = ref(false);

const columns = ref < JVxeColumn[] > ([
    {
        title: '主商家编码',
        key: 'mainouterid',
        type: JVxeTypes.normal,
        width: 180,
        ShowOverflow:false
    },
    {
        title: '商品名称',
        key: 'title',
        type: JVxeTypes.normal,
        width: 400,
    },
    {
        title: '实际总库存数',
        key: 'totalavailablestocksum',
        type: JVxeTypes.normal,
        width: 180,
    },
    {
        title: '实际锁定库存',
        key: 'totallockstock',
        type: JVxeTypes.normal,
        width: 180,
    },
    {
        title: '实际可用库存',
        key: 'totalavailablestock',
        type: JVxeTypes.normal,
        width: 180,
    },
]);
const dataSource = ref<any[]>([]);
const sexOptions = ref([
    { label: '男', value: '1' },
    { label: '女', value: '2' },
])
 
async function loadData() {
    //dataSource.value.push(listAsync(1));
    loading.value = true;
    await listAsync(1).then((result) => {
        loading.value = false;
        dataSource.value = result;
        // let values: any[] = [];

     }     
    );
    
}

async function flushStock() {
    loading.value = true;
    await flushstock().then(() => {
        loading.value = false;
     }
    );

}
</script>
